package com.meishij.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v4.util.Pools;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioGroup;

import com.facebook.drawee.generic.GenericDraweeHierarchyBuilder;
import com.facebook.drawee.view.SimpleDraweeView;
import com.meishij.entry.ShihuaEntry;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/12.
 * 我是youngKaka 我的心愿是世界和平
 */

public class ShiHua_Banner_VP_Adapter extends PagerAdapter {

    private Context context;
    private List<ShihuaEntry.Activities2Bean> listBean;
    private Pools.Pool<SimpleDraweeView> pool = new Pools.SimplePool<>(6);

    public ShiHua_Banner_VP_Adapter(Context context, List<ShihuaEntry.Activities2Bean> list) {
        this.context = context;
        listBean = new ArrayList<>();
        listBean.add(list.get(list.size() - 1));
        listBean.addAll(list);
        listBean.add(list.get(0));
    }

    @Override
    public int getCount() {
        return listBean == null ? 0 : listBean.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        SimpleDraweeView simpleDraweeView = pool.acquire();
        if (simpleDraweeView == null) {
            simpleDraweeView = new SimpleDraweeView(context);
        }
        Uri uri = Uri.parse(listBean.get(position).getImg());
        simpleDraweeView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        simpleDraweeView.setImageURI(uri);
        container.addView(simpleDraweeView);
        return simpleDraweeView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
